# -*- codeing = utf-8 -*-
# @Time : 2021/8/19 9:08
# @Author : xiaow
# @File : ReuqestUtil.py
# @Software : PyCharm
import time

import requests
from api import wordcloudutil

header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400",
    "accept": "application/json, text/plain, */*"
}


def getJson(url):
    r = requests.get(url, headers=header)
    return r.json()['comments']


if __name__ == '__main__':
    text = ''
    songId = "210049"
    page = 1
    url = "http://music.163.com/api/v1/resource/comments/R_SO_4_{0}?limit=100&offset={1}".format(songId, str(page))

    comments = getJson(url)
    for i in range(1, 15):
        for c in comments:
            text = text + c['content']
    wordcloudutil.getWordCloud(text)
